#include <iostream>
using namespace std;

/*
    我要直接打印猫的信息
      1.以前打印猫的信息，都是调用show方法
      2.受到cout打印底层原理的启发，搞定cout输出猫所有的信息
        具体分析如下
          cat << c1;
          函数调用 cat.operator<<(c1);
            利用友元函数 operator<<(ostream &os, Cat &c1)
*/

class Cat
{
public:
    Cat(string name, int age)
    {
        this->name = name;
        this->age = age;
    }

    friend ostream &operator<<(ostream &os, Cat &c1)
    {
        os << "name:" << c1.name << " age:" << c1.age << endl;
        return os;
    }

private:
    string name;
    int age;
};

int main()
{
    Cat c1("Tom", 10);
    Cat c2("Jerry", 20);

    cout << c1 << c2;
    return 0;
}